package  com.songyl.patternLearn.AdapterPattern;

public class PlayerAdapter extends Player {

    HighLevelPlayer highLevelPlayer;

    public PlayerAdapter(String level,float... hps){

        if("LV2".equals(level)){
            highLevelPlayer=new PlayerLV2();
        }else if("LV3".equals(level)){
            highLevelPlayer=new PlayerLV3();
        }
        highLevelPlayer.setLevel(level);
        for (int i = 0; i < hps.length; i++) {
            highLevelPlayer.addHP(hps[i]);
        }

    }

    @Override
    public boolean play() {
        for (int i = 0; i < highLevelPlayer.HPList.size(); i++) {
            highLevelPlayer.setHP(highLevelPlayer.HPList.get(i));
            printInfo();
            if(!highLevelPlayer.isAlive()&&highLevelPlayer.relive()){
                System.out.println("----> 当前 "+highLevelPlayer.getLevel()+" 玩家 第 "+(highLevelPlayer.getReliveTime()+" 次复活"));
                highLevelPlayer.setHP(100);
                printInfo();

            }
            if(!highLevelPlayer.isAlive()){
                break;
            }


        }



        return false;
    }
    public void printInfo(){
        System.out.println("当前 "+highLevelPlayer.getLevel()+" 玩家的生命：HP ="+highLevelPlayer.getHP());
        System.out.println("当前 "+highLevelPlayer.getLevel()+" 玩家 "+(highLevelPlayer.isAlive()?"活着":"死了"));

    }
}
